package com.authine.cloudpivot.ext.service.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
import com.alibaba.xxpt.gateway.shared.client.http.PostClient;
import com.authine.cloudpivot.ext.service.IZzdOrgApiService;
import com.authine.cloudpivot.ext.service.base.ZzdBaseServiceImpl;

/**
 * 专有钉组织架构接口
 * 
 * @author shinka
 * @date 2021/07/13
 */
@Service
public class ZzdOrgApiServiceImpl extends ZzdBaseServiceImpl implements IZzdOrgApiService {

    private static final Logger log = LoggerFactory.getLogger(ZzdOrgApiServiceImpl.class);

    @Override
    public String getEmployeeByCode(Map<String, String> params) {
        if (log.isDebugEnabled()) {
            log.debug("getEmployeeByCode params={}", params);
        }

        ExecutableClient executableClient = getExecutableClient(params);
        String api = "/mozi/employee/getEmployeeByCode";
        PostClient postClient = executableClient.newPostClient(api);
        // 设置参数
        postClient.addParameter("employeeCode", params.get("employeeCode"));
        postClient.addParameter("tenantId", params.get("tenantId"));

        // 调用API
        String apiResult = postClient.post();
        return apiResult;
    }

    @Override
    public String listEmployeePositionsByEmployeeCode(Map<String, String> params) {
        if (log.isDebugEnabled()) {
            log.debug("listEmployeePositionsByEmployeeCode params={}", params);
        }

        ExecutableClient executableClient = getExecutableClient(params);
        String api = "/mozi/employee/listEmployeePositionsByEmployeeCode";
        PostClient postClient = executableClient.newPostClient(api);
        // 设置参数
        postClient.addParameter("employeeCode", params.get("employeeCode"));
        postClient.addParameter("tenantId", params.get("tenantId"));
        // postClient.addParameter("employeePositionStatus", params.get("employeePositionStatus"));
        postClient.addParameter("employeePositionType", params.get("employeePositionType"));

        // 调用API
        String apiResult = postClient.post();
        return apiResult;
    }

    @Override
    public String getOrganizationByCode(Map<String, String> params) {
        if (log.isDebugEnabled()) {
            log.debug("getOrganizationByCode params={}", params);
        }

        ExecutableClient executableClient = getExecutableClient(params);
        String api = "/mozi/organization/getOrganizationByCode";
        PostClient postClient = executableClient.newPostClient(api);
        // 设置参数
        postClient.addParameter("organizationCode", params.get("organizationCode"));
        postClient.addParameter("tenantId", params.get("tenantId"));

        // 调用API
        String apiResult = postClient.post();
        return apiResult;
    }

}
